//#ifndef NETWORK_MODEL_EMESH_HOP_COUNTER_H
//#define NETWORK_MODEL_EMESH_HOP_COUNTER_H
//
//#include "network.h"
//#include "network_model.h"
//#include "lock.h"
//
//class NetworkModelEMeshHopCounter : public NetworkModel
//{
//public:
//   NetworkModelEMeshHopCounter(Network *net, EStaticNetwork net_type);
//   ~NetworkModelEMeshHopCounter();
//
//   void routePacket(const NetPacket &pkt,
//                    std::vector<Hop> &nextHops);
//   void processReceivedPacket(NetPacket &pkt);
//
//   void enable() { _enabled = true; }
//   void disable() { _enabled = false; }
//
//private:
//
//   void computePosition(core_id_t core, SInt32 &x, SInt32 &y);
//   SInt32 computeDistance(SInt32 x1, SInt32 y1, SInt32 x2, SInt32 y2);
//
//   SubsecondTime computeSerializationLatency(UInt32 pkt_length);
//
//   ComponentLatency _hopLatency;
//   ComponentBandwidthPerCycle _linkBandwidth;
//
//   SInt32 _meshWidth;
//   SInt32 _meshHeight;
//
//   bool _enabled;
//
//   Lock _lock;
//
//   // Performance Counters
//   UInt64 _num_packets;
//   UInt64 _num_bytes;
//   SubsecondTime _total_latency;
//};
//
//#endif


#ifndef NETWORK_MODEL_EMESH_HOP_COUNTER_H
#define NETWORK_MODEL_EMESH_HOP_COUNTER_H

#include "network.h"
#include "network_model.h"
#include "lock.h"
#include "stats.h" // ✅ 因为 registerStatsMetric 是这里定义的


class NetworkModelEMeshHopCounter : public NetworkModel
{
public:
    NetworkModelEMeshHopCounter(Network *net, EStaticNetwork net_type);
    ~NetworkModelEMeshHopCounter();

    SInt32 computeChipletID();

    void routePacket(const NetPacket &pkt,
                     std::vector<Hop> &nextHops);
    void processReceivedPacket(NetPacket &pkt);

    void enable() { _enabled = true; }
    void disable() { _enabled = false; }

private:

    //  统计片间通信量
    UInt64 _intra_chiplet_bytes;
    UInt64 _inter_chiplet_bytes;

    void computePosition(core_id_t core, SInt32 &x, SInt32 &y);
    SInt32 computeDistance(SInt32 x1, SInt32 y1, SInt32 x2, SInt32 y2);
    SubsecondTime computeSerializationLatency(UInt32 pkt_length);

    ComponentLatency _hopLatency;
    ComponentBandwidthPerCycle _linkBandwidth;

    ComponentLatency _intraChipletLatency;   // ✅ 片内通信延迟
    ComponentBandwidthPerCycle _intraChipletBandwidth;

    ComponentLatency _interChipletLatency;   // ✅ 片间通信延迟
    ComponentBandwidthPerCycle _interChipletBandwidth;

    ComponentLatency _ioDieLatency;
    ComponentBandwidthPerCycle _ioDieBandwidth;
    bool _useIoDie;

    // 多芯粒结构
    SInt32 _totalCores;      // 总核心数
    SInt32 _coresPerChiplet; // 每个芯粒的核心数
    SInt32 _chipletWidth;    // 每个芯粒的宽度（x 方向）
    SInt32 _chipletHeight;   // 每个芯粒的高度（y 方向）
    SInt32 _numChipletsX;    // 芯粒横向数量
    SInt32 _numChipletsY;    // 芯粒纵向数量

    // 计算核心所属芯粒 ID
    SInt32 computeChipletID(core_id_t core);

    // 芯粒拓扑结构
    enum InterChipletTopology { MESH, BUS, HYBRID };
    InterChipletTopology _interChipletTopology;

    SInt32 _meshWidth;
    SInt32 _meshHeight;

    bool _enabled;

    Lock _lock;

    // Performance Counters
    UInt64 _num_packets;
    UInt64 _num_bytes;
    SubsecondTime _total_latency;
};

#endif
